
package com.kugou.game.sdk.core;

import java.util.ArrayList;
import java.util.concurrent.Executors;

import com.kugou.game.sdk.entity.CouponHelpInfo;
import com.kugou.game.sdk.interfaces.OnRequestListener;
import com.kugou.game.sdk.protocol.RequestCouponHelpInfoTask;
import com.kugou.game.sdk.protocol.RequestCouponHelpInfoTask.CouponInfoHelpResponse;

public class CouponHelpModel {

    private static CouponHelpModel sCouponHelpModel;

    private static ArrayList<CouponHelpInfo> mHelpInfos;

    private CouponHelpModel() {

    }

    public synchronized static CouponHelpModel getCouponHelpModel() {

        if (sCouponHelpModel == null) {
            sCouponHelpModel = new CouponHelpModel();
        }

        return sCouponHelpModel;
    }

    public void requestHelpInfos(final OnRequestListener listener) {
        Executors.newCachedThreadPool().execute(new Runnable() {

            @Override
            public void run() {
                CouponInfoHelpResponse response = new RequestCouponHelpInfoTask().request();
                if (response != null) {
                    if (response.isOk()) {
                        if (listener != null) {
                            mHelpInfos = response.getCouponInfos();
                            listener.onSuccess();
                        }
                    } else {
                        if (listener != null) {
                            listener.onFailed(response.getPrompt());
                        }
                    }
                } else {
                    if (listener != null) {
                        listener.onFailed("网络请求失败");
                    }
                }
            }
        });
    }

    public ArrayList<CouponHelpInfo> getHelpInfos() {
        return mHelpInfos;
    }

}
